#ifndef _HJ212_CLIENT_PORT_H
#define _HJ212_CLIENT_PORT_H

#include "hj212_client_def.h"

#define hj212_client_command(client, cmd, args) \
    (client->ops->command ? client->ops->command(client, cmd, args) : -1)
#define hj212_client_current_timestamp(client) \
    (client->ops->current_timestamp ? client->ops->current_timestamp() : 0)
#define hj212_client_set_current_timestamp(client, time) \
    (client->ops->set_current_timestamp ? client->ops->set_current_timestamp(time) : -1)
#define hj212_client_current_subsec(client) \
    (client->ops->current_subsec ? client->ops->current_subsec() : ((struct timeval){.tv_sec = 0, .tv_usec = 0}))
#define hj212_client_lock(client) \
    (client->ops->lock ? client->ops->lock(client) : 0)
#define hj212_client_trylock(client) \
    (client->ops->trylock ? client->ops->trylock(client) : 0)
#define hj212_client_unlock(client) \
    (client->ops->unlock ? client->ops->unlock(client) : 0)
#define hj212_client_malloc(client, size) \
    (client->ops->malloc ? client->ops->malloc(size) : NULL)
#define hj212_client_calloc(client, num, size) \
    (client->ops->calloc ? client->ops->calloc(num, size) : NULL)
#define hj212_client_free(client, ptr) \
    (client->ops->free ? client->ops->free(ptr) : 0)
#define hj212_client_dev_open(client, flag) \
    (client->ops->dev_open ? client->ops->dev_open(client, flag) : 0)
#define hj212_client_dev_close(client) \
    (client->ops->dev_close ? client->ops->dev_close(client) : 0)
#define hj212_client_dev_state(client) \
    (client->ops->dev_state ? client->ops->dev_state(client) : 0)
#define hj212_client_dev_recv(client, buffer, len, timeout) \
    (client->ops->dev_recv ? client->ops->dev_recv(client, buffer, len, timeout) : 0)
#define hj212_client_dev_send(client, buffer, len) \
    (client->ops->dev_send ? client->ops->dev_send(client, (uint8_t *)buffer, len) : -1)
#define hj212_client_get_data_source(client, type) \
    (client->ops->get_data_source ? client->ops->get_data_source(client, type) : NULL)
#define hj212_client_create_hisdata_source(client, type, begin, end) \
    (client->ops->create_hisdata_source ? client->ops->create_hisdata_source(client, type, begin, end) : NULL)
#define hj212_client_delete_data_source(client, source) \
    (client->ops->delete_data_source ? client->ops->delete_data_source(client, source) : 0)
#define hj212_client_event_push(client, event) \
    (client->ops->event_push ? client->ops->event_push(client, event) : 0)


int hj212_client_init(struct hj212_client *client, int id,
                      enum hj212_protocol_type protocol,
                      const struct hj212_client_ops *ops);
void hj212_client_destroy(struct hj212_client *client);

#endif
